//
//  ViewController.m
//  UI_18_SQLite
//
//  Created by li cheng on 16/8/8.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "ViewController.h"
#import "SQLiteDataBaseManager.h"

@interface ViewController ()
@property (nonatomic, strong) SQLiteDataBaseManager *dataBaseManager;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _dataBaseManager = [SQLiteDataBaseManager sharedManger];
    // SQLite3
    // 注意: 使用SQLite需要引入libsqlite3.0tdb
    // libsqlite3.0 和 libsqlite3的区别
    // libsqlite3.0 是 libsqlite3的替身文件, 防止用户误删;
}
- (IBAction)openSQLite:(id)sender {
    [_dataBaseManager openSQLite3];
}
- (IBAction)colseSQLite:(id)sender {
    [_dataBaseManager closeSQLite3];
}
- (IBAction)createTable:(id)sender {
    [_dataBaseManager cerateSQLite3];
}

- (IBAction)insertStu:(id)sender {
    Student *stu = [[Student alloc] init];
    stu.stu_id = 14;
    stu.stu_name = @"姜浩";
    [_dataBaseManager insertStu:stu];
}

- (IBAction)deleteStu:(id)sender {
//    [_dataBaseManager deleteAll];
    Student *stu = [[Student alloc] init];
    stu.stu_id = 11;
    [_dataBaseManager deleteStu:stu];
}
- (IBAction)updateName:(id)sender {
    [_dataBaseManager updateOldName:@"姜浩" newName:@"xxx"];
}
- (IBAction)selectAll:(id)sender {
    NSArray *array = [_dataBaseManager selectAll];
    NSLog(@"%ld", array.count);
    NSLog(@"%@", array);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
